VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form ailments 
   BorderStyle     =   0  'None
   Caption         =   "Edit Ailment List"
   ClientHeight    =   6180
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   7320
   LinkTopic       =   "Form2"
   ScaleHeight     =   6180
   ScaleWidth      =   7320
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command3 
      Caption         =   "Command3"
      Height          =   495
      Left            =   1560
      TabIndex        =   10
      Top             =   5640
      Width           =   1935
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   2160
      Top             =   120
      Visible         =   0   'False
      Width           =   5055
      _ExtentX        =   8916
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   $"ailments.frx":0000
      OLEDBString     =   $"ailments.frx":00A4
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "ailments"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Return"
      Height          =   495
      Left            =   5520
      TabIndex        =   9
      Top             =   5640
      Width           =   1695
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   3600
      TabIndex        =   8
      Top             =   5640
      Width           =   1815
   End
   Begin VB.TextBox Text2 
      Height          =   1335
      Left            =   120
      TabIndex        =   7
      Text            =   "Text2"
      Top             =   4200
      Width           =   7095
   End
   Begin VB.TextBox Text1 
      Height          =   285
      Left            =   1440
      TabIndex        =   5
      Text            =   "Text1"
      Top             =   3600
      Width           =   5775
   End
   Begin VB.ComboBox Combo1 
      DataSource      =   "Adodc1"
      Height          =   315
      Left            =   1440
      TabIndex        =   3
      Text            =   "-SELECT ONE-"
      Top             =   3240
      Width           =   5775
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "ailments.frx":0148
      Height          =   2535
      Left            =   120
      TabIndex        =   1
      Top             =   600
      Width           =   7095
      _ExtentX        =   12515
      _ExtentY        =   4471
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      FormatLocked    =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   3
      BeginProperty Column00 
         DataField       =   "ID"
         Caption         =   "ID"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   "ailment"
         Caption         =   "ailment"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column02 
         DataField       =   "details"
         Caption         =   "details"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
            ColumnWidth     =   915.024
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column02 
            ColumnWidth     =   1739.906
         EndProperty
      EndProperty
   End
   Begin VB.Label Label4 
      Caption         =   "Description"
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   3960
      Width           =   1335
   End
   Begin VB.Label Label3 
      Caption         =   "Ailment"
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   3600
      Width           =   1215
   End
   Begin VB.Label Label2 
      Caption         =   "Select ailment"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   3240
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "List of Ailments"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
End
Attribute VB_Name = "ailments"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private recID

Private Sub Combo1_Click()
With Adodc1.Recordset
    Select Case Combo1.Text
    Case "-SELECT ONE-"
        Text1.Enabled = False
        Text2.Enabled = False
        Command1.Caption = "Command1"
        Command1.Visible = False
    Case "-ADD NEW-"
        Text1.Text = ""
        Text1.Enabled = True
        Text2.Text = ""
        Text2.Enabled = True
        Command1.Caption = "Save"
        Command1.Visible = True
    Case Else
        Text1.Enabled = True
        Text2.Enabled = True
        .MoveFirst
        While Not .EOF
            If .Fields("ailment") = Combo1.Text Then
                recID = .Fields("ID")
                Text1.Text = .Fields("ailment")
                Text2.Text = .Fields("details")
                Command1.Caption = "Edit"
                Command1.Visible = True
                Command3.Caption = "Delete"
                Command3.Visible = True
            End If
            .MoveNext
        Wend
    End Select
End With
End Sub

Private Sub Command1_Click()
    With Adodc1.Recordset
        If Not Text1.Text = "" Then
            Select Case Command1.Caption
                Case "Save"
                    .AddNew
                    .Fields("ailment") = Text1.Text
                    .Fields("details") = Text2.Text
                    .Update
                    clearAll
                Case "Edit"
                    .MoveFirst
                    While Not .EOF
                        If .Fields("ID") = recID Then
                            .Fields("ailment") = Text1.Text
                            .Fields("details") = Text2.Text
                            .Update
                            clearAll
                        End If
                        .MoveNext
                    Wend
                Case Else
                    MsgBox "Error!"
            End Select
            rebuildComboBox
        Else
            MsgBox "Ailment name cannot be null!"
        End If
    End With
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

Private Sub Command3_Click()
    With Adodc1.Recordset
        .MoveFirst
        Do While Not .EOF
            If .Fields("ID") = recID Then Exit Do
            .MoveNext
        Loop
        .Delete
        .Update
        clearAll
    End With
    rebuildComboBox
End Sub

Private Sub Form_Load()
    clearAll
    With Adodc1.Recordset
        .MoveFirst
        While Not .EOF
            Combo1.AddItem (.Fields("ailment"))
            .MoveNext
        Wend
        Combo1.AddItem ("-ADD NEW-")
    End With
End Sub

Sub clearAll()
        Text1.Text = ""
        Text1.Enabled = False
        Text2.Text = ""
        Text2.Enabled = False
        Combo1.Text = "-SELECT ONE-"
        Command1.Visible = False
        Command3.Visible = False
End Sub

Sub rebuildComboBox()
    Form1.Combo1.Clear
    Form1.Combo1.Text = "-SELECT ONE-"
    Combo1.Clear
    Combo1.Text = "-SELECT ONE-"
    With Adodc1.Recordset
        .MoveFirst
        While Not .EOF
            Form1.Combo1.AddItem (.Fields("ailment"))
            Combo1.AddItem (.Fields("ailment"))
            .MoveNext
        Wend
    End With
    Combo1.AddItem ("-ADD NEW-")
End Sub
